package com.chaoxin.lovehelp.controller;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.Map;

import com.chaoxin.lovehelp.common.enums.vo.recipientRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.chaoxin.lovehelp.entity.ActivityRecordEntity;
import com.chaoxin.lovehelp.service.ActivityRecordService;
import com.chaoxin.lovehelp.common.utils.PageUtils;
import com.chaoxin.lovehelp.common.utils.R;

import javax.servlet.http.HttpServletRequest;


/**
 * 
 *
 * @author honghu
 * @email 3027708213@qq.com
 * @date 2024-02-04 22:13:14
 */
@RestController
@CrossOrigin
@RequestMapping("lovehelp/activityrecord")
public class ActivityRecordController {
    @Autowired
    private ActivityRecordService activityRecordService;

    /**
     * 受助记录列表
     */
    @RequestMapping("/list")
    public R list(HttpServletRequest request, @RequestParam Map<String, Object> params) throws ParseException {
        PageUtils page = activityRecordService.queryPage(request,params);

        return R.ok().put("page", page);
    }
    /**
     * 导出数据
     */
    @RequestMapping("/exportrecord")
    public R exportRecord(@RequestParam Map<String, Object> params) throws ParseException, UnsupportedEncodingException {
        activityRecordService.exportRecord(params);
        return R.ok();
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        recipientRecordVo vo = activityRecordService.getVoById(id);
        activityRecordService.deleteAliyunPicTask();
        return R.ok().put("activityRecord", vo);
    }
//
//    /**
//     * 保存
//     */
//    @RequestMapping("/save")
//    public R save(@RequestBody ActivityRecordEntity activityRecord){
//		activityRecordService.save(activityRecord);
//
//        return R.ok();
//    }
//
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ActivityRecordEntity activityRecord){
        ActivityRecordEntity record = activityRecordService.getById(activityRecord.getId());
        if(activityRecord.getDetail()!=null)
        record.setDetail(activityRecord.getDetail());
        record.setDetailPic(activityRecord.getDetailPic());
		activityRecordService.updateById(record);
        return R.ok();
    }



}
